package com.ruoyi.service.impl;

import com.hundun.vision.api.common.PlainResult;
import com.hundun.vision.api.dto.OperatorDTO;
import com.hundun.vision.api.service.RPCOperatorService;
import com.ruoyi.common.utils.ResultUtils;
import com.ruoyi.service.OperatorService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author ：RuoChen
 * @date ：22:58 2021/6/14
 * @description：运算符服务实现类
 */
@Slf4j
@Component
public class OperatorServiceImpl implements OperatorService {

    @DubboReference(timeout = 60000, retries = 0)
    private RPCOperatorService operatorService;

    @Override
    public OperatorDTO getById(Long operatorId) {
        log.info("get operator by id,operatorId:{}", operatorId);
        PlainResult<OperatorDTO> result = operatorService.getById(operatorId);
        if (result.isSuccess()) {
            return result.getData();
        } else {
            ResultUtils.error(result.getMessage());
        }
        return null;
    }

    @Override
    public List<OperatorDTO> list() {
        log.info("list operator");
        PlainResult<List<OperatorDTO>> result = operatorService.list();
        if (result.isSuccess()) {
            return result.getData();
        } else {
            ResultUtils.error(result.getMessage());
        }
        return null;
    }
}
